﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using EAF.Utility;

namespace App.Utility.ComEntity
{
    /*******************************项目中所有请求响应实体*********************************/

    #region 常用请求对象

    /// <summary>
    /// 批量操作id 比如设置启用状态 不支持设置不同状态
    /// </summary>
    /// <typeparam name="T">id类型</typeparam>
    [Serializable]
    public partial class Json_ReqIds<T>
    {
        /// <summary>
        /// 批量操作id
        /// </summary>
        public List<T> ids { get; set; }

        /// <summary>
        /// 操作模式
        /// </summary>
        public int mode { get; set; }

        /// <summary>
        /// 操作表
        /// </summary>
        public string tableName { get; set; }
    }
    /// <summary>
    /// 通过id操作指定字段 比如设置连接状态 设置不同状态
    /// </summary>
    [Serializable]
    public partial class Json_Req4IdOP
    {
        /// <summary>
        /// 批量操作id和字段结果
        /// </summary>
        public List<IdFR> idr { get; set; }

        /// <summary>
        /// 操作模式
        /// </summary>
        public int mode { get; set; }

        /// <summary>
        /// 操作表
        /// </summary>
        public string tableName { get; set; }

        public class IdFR
        {
            public int id { get; set; }

            public int result { get; set; }
        }
    }

    #endregion

    #region 常用响应对象

    /// <summary>
    /// JsonParamError 参数验证错误 用于整理mvc参数验证结果
    /// </summary>
    [Serializable]
    public class JsonParamError
    {
        /// <summary>
        /// 总条数
        /// </summary>
        public int errorTotal { get; set; }

        /// <summary>
        /// 简略消息 提示给用户看
        /// </summary>
        public List<string> simpleMessage { get; set; }

        /// <summary>
        /// 所有错误消息
        /// </summary>
        public List<FieldError> errorFieldInfo { get; set; }

        public class FieldError
        {
            /// <summary>
            /// 错误字段名
            /// </summary>
            public string field { get; set; }

            /// <summary>
            /// 错误消息
            /// </summary>
            public List<string> errorMsg { get; set; }
        }
    }

    /// <summary>
    /// JsonImportError 参数验证错误 用于导入excel
    /// </summary>
    [Serializable]
    public class JsonImportError
    {
        /// <summary>
        /// 总条数
        /// </summary>
        public int errorTotal { get; set; }

        /// <summary>
        /// 简略消息 提示给用户看
        /// </summary>
        public List<string> simpleMessage { get; set; }

        ///// <summary>
        ///// 所有错误消息
        ///// </summary>
        //public Dictionary<int, Dictionary<string, List<string>>> errorInfo { get; set; }

    }

    /// <summary>
    /// 返回任意类型实体用
    /// </summary>
    [Serializable]
    public class JsonR : JsonKeyValue
    {
        public JsonR()
        {
            code = -1;
            message = string.Empty;
            body = null;
        }
        /// <summary>
        /// 返回码
        /// </summary>
        public int code { get; set; }
        /// <summary>
        /// 返回说明
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// 返回数据体 可为空
        /// </summary>
        public object body { get; set; }
    }

    /// <summary>
    /// 返回泛型实体用
    /// </summary>
    /// <typeparam name="T">返回结果Body类型</typeparam>
    [Serializable]
    public class JsonR<T> : JsonKeyValue
    {
        public JsonR()
        {
            code = -1;
            message = string.Empty;
            body = default;
        }
        /// <summary>
        /// 返回码
        /// </summary>
        public int code { get; set; }
        /// <summary>
        /// 返回说明
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// 返回数据体 可为空
        /// </summary>
        public T body { get; set; }
    }

    /// <summary>
    /// 分页数据接口返回的列表对象 用于给 JsonR 的 Body 赋值
    /// </summary>
    [Serializable]
    public class JsonPage : JsonKeyValue
    {
        /// <summary>
        /// 当前页码
        /// </summary>
        public int page { get; set; }
        /// <summary>
        /// 每页条数
        /// </summary>
        public int pageSize { get; set; }
        /// <summary>
        /// 总条数
        /// </summary>
        public int total { get; set; }
        /// <summary>
        /// 数据对象
        /// </summary>
        public IEnumerable<object> list { get; set; }
    }

    /// <summary>
    /// 分页数据接口返回的列表对象 用于给 JsonR 的 Body 赋值 泛型可在文档显示注释
    /// </summary>
    [Serializable]
    public class JsonPage<T>
    {
        /// <summary>
        /// 当前页码
        /// </summary>
        public int pageIndex { get; set; }
        /// <summary>
        /// 每页条数
        /// </summary>
        public int pageSize { get; set; }
        /// <summary>
        /// 总条数
        /// </summary>
        public int total { get; set; }
        /// <summary>
        /// 附加数据
        /// </summary>
        public object tagData { get; set; }
        /// <summary>
        /// 数据对象
        /// </summary>
        public IEnumerable<T> list { get; set; }

    }

    #endregion

    #region 字典响应

    [Serializable]
    public class JsonKeyValue
    {
        /// <summary>
        /// 键对值字典列表
        /// </summary>
        public Dictionary<string, List<EnumTableKeyValue>> keyValue { get; set; }

    }

    #endregion

    #region 队列传输 日志实体

    /// <summary>
    /// 普通日志实体  注意要使用RabbitQueue对应的通道
    /// </summary>
    [Serializable]
    public class RLogNormal
    {
        /// <summary>
        /// 日志级别 
        /// </summary>
        public virtual LogLevel? Level { get; set; }
        /// <summary>
        /// 详细内容 
        /// </summary>
        public virtual string Content { get; set; }
        /// <summary>
        /// 平台id
        /// </summary>
        public virtual int PlatformId { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public virtual string Description { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public virtual DateTime CreateTime { get; set; }
        /// <summary>
        /// 创建者编号
        /// </summary>
        public virtual int? CreaterId { get; set; }
        /// <summary>
        /// 创建者名称
        /// </summary>
        public virtual string CreaterName { get; set; }
    }

    /// <summary>
    /// 请求日志 app端暂时公用  注意要使用RabbitQueue对应的通道
    /// </summary>
    [Serializable]
    public class RLogRequest : RLogNormal
    {
        public RLogRequest()
        {
            this.PlatformId = AppData.PlatformId;
            this.CreateTime = DateTime.Now;
        }
        /// <summary>
        /// 接口地址
        /// </summary>
        public virtual string ApiUrl { get; set; }
        /// <summary>
        /// 消耗时间 毫秒
        /// </summary>
        public virtual float? SpendTime { get; set; }
        /// <summary>
        /// 请求ip
        /// </summary>
        public virtual string ReqIp { get; set; }
        /// <summary>
        /// 请求客户端
        /// </summary>
        public virtual string Browser { get; set; }
        /// <summary>
        /// 请求参数
        /// </summary>
        public virtual string ReqParam { get; set; }
        /// <summary>
        /// 响应结果
        /// </summary>
        public virtual string Result { get; set; }

    }

    /// <summary>
    /// 业务操作日志  注意要使用RabbitQueue对应的通道
    /// </summary>
    public class RLogBehavior : RLogNormal
    {
        public RLogBehavior()
        {
            this.PlatformId = AppData.PlatformId;
            this.CreateTime = DateTime.Now;
        }
        /// <summary>
        /// 操作涉及的表名
        /// </summary>
        public string Table { get; set; }
        /// <summary>
        /// 操作方法
        /// </summary>
        public EntityMethod Method { get; set; }
    }

    /// <summary>
    /// 操作类型
    /// </summary>
    public enum EntityMethod
    {
        [Description("添加")]
        M_添加 = 1,
        [Description("删除")]
        M_删除 = 2,
        [Description("修改")]
        M_修改 = 3,
        [Description("查看")]
        M_查看 = 4,
        //[Description("导入")]
        //M_导入 = 5,
        //[Description("导出")]
        //M_导出 = 6,
        [Description("还原")]
        M_还原 = 7,
        [Description("销毁")]
        M_销毁 = 8,
        //[Description("批量更新")]
        //M_批量更新 = 9,
        //[Description("登入系统")]
        //M_登入系统 = 10,
        //[Description("登出系统")]
        //M_登出系统 = 11,
        //[Description("修改密码")]
        //M_修改密码 = 12,
        //[Description("录取查看")]
        //M_录取查看 = 13,
        //[Description("分班")]
        //M_分班 = 14,
        //[Description("分学号")]
        //M_分学号 = 15,
        //[Description("归还")]
        //M_归还 = 16,
        //[Description("延长归还时间")]
        //M_延长归还时间 = 17,
        //[Description("排课")]
        //M_排课 = 18,
        //[Description("发送短信")]
        //M_发送短信 = 19,
        //[Description("复制")]
        //M_复制 = 20,
    }

    #endregion

    #region id name 键对值

    /// <summary>
    /// 页面数据传输过程中,用于储存键值对
    /// </summary>
    [Serializable]
    public class JsonIdName
    {
        public JsonIdName() { id = 0; name = string.Empty; }
        public JsonIdName(int i, string n)
        {
            id = i;
            name = n;
        }
        /// <summary>
        /// id
        /// </summary> 
        public int id { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string name { get; set; }
    }

    /// <summary>
    /// 页面数据传输过程中,用于储存键值对 支持英文名
    /// </summary>
    [Serializable]
    public class JsonIdNameAndEnName
    {
        public JsonIdNameAndEnName() { id = 0; name = string.Empty; enName = string.Empty; }
        public JsonIdNameAndEnName(int i, string n, string en)
        {
            id = i;
            name = n;
            enName = en;
        }
        /// <summary>
        /// id
        /// </summary> 
        public int id { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string name { get; set; }
        /// <summary>
        /// 英文名称
        /// </summary>
        public string enName { get; set; }
    }

    /// <summary>
    /// 页面数据传输过程中,用于储存键值对 id类型为字符串
    /// </summary>
    [Serializable]
    public class JsonIdNameStr
    {
        public JsonIdNameStr() { id = "0"; name = string.Empty; }
        public JsonIdNameStr(string id, string name)
        {
            this.id = id;
            this.name = name;
        }
        /// <summary>
        /// id
        /// </summary> 
        public string id { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string name { get; set; }
    }

    #endregion

    #region JsonTime 相应一个时间段

    /// <summary>
    /// 页面数据传输过程中,用于存储时间范围
    /// </summary>
    [Serializable]
    public class JsonTime
    {
        public JsonTime(string s, string e)
        {
            start = s;
            end = e;
        }

        public string start { get; set; }
        public string end { get; set; }
    }

    #endregion

    #region JsonHTML 小程序编辑器用
    [Serializable]
    public class JsonHTML
    {
        public string resource { get; set; }
        public string html { get; set; }
    }
    #endregion


}
